Imports System.Windows.Forms

Public Class dlgCard

    Dim dt As New DataTable
    Dim sql As String

    Private Sub btnFindbyEmployee_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindbyEmployee.Click
        sql = "select CardNumberID as 'CardNumber',cActive as 'Active',cNote as 'Note',cCreatedby as 'Created by' from CardNumber_CuChi  where CardNumberID in (select eCardNumber from  Employee_CuChi  where  EmployeeID like '%" & txtFind.Text.Replace("'", "''") & "%' or " _
            & " eFullName like '%" & txtFind.Text.Replace("'", "''") & "%')"
        bindSQL(sql)
    End Sub

    Private Sub btnFindbyCardNumber_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFindbyCardNumber.Click
        FindByCardNumber()
    End Sub
    Public Sub FindByCardNumber()
        sql = "select CardNumberID as 'CardNumber',cActive as 'Active',cNote as 'Note',cCreatedby as 'Created by' from CardNumber_CuChi  where  CardNumberID like '%" & txtFind.Text.Replace("'", "''") & "%'"
        bindSQL(sql)
    End Sub
    Private Sub bindSQL(ByVal sql As String)
        Dim bs As New BindingSource
        dt = db.getvalue(sql).Tables(0)
        bs.DataSource = dt
        dgvCardNumber.DataSource = bs

        For i As Integer = 0 To dt.Columns.Count - 1
            dgvCardNumber.Columns(i).Name = dgvCardNumber.Columns(i).HeaderText
        Next
        dgvCardNumber.Columns("CardNumber").ReadOnly = True
        dgvCardNumber.Columns("Created by").ReadOnly = True
        dgvCardNumber.AllowUserToDeleteRows = False
        dgvCardNumber.AllowUserToAddRows = False
        dgvCardNumber.Columns("active").Width = 50
        dgvCardNumber.Columns("note").Width = 200
    End Sub


    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Try
            If dt.Rows.Count > 0 Then
                db.updateTable(dt, sql)
                MsgBox("Saved!!!", MsgBoxStyle.Information)
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        
    End Sub



    Private Sub dgvCardNumber_MouseHover(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgvCardNumber.MouseHover
       
    End Sub

    Private Sub dgvCardNumber_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles dgvCardNumber.MouseMove
        'Dim pstart, pend As Integer

        'pstart = Me.Location.Y + dgvCardNumber.Location.Y + dgvCardNumber.ColumnHeadersHeight + 22

        'For i As Integer = 0 To dgvCardNumber.Rows.Count - 1
        '    pend = pstart + dgvCardNumber.Rows(i).Height
        '    If dgvCardNumber.MousePosition.Y > pstart _
        '    And dgvCardNumber.MousePosition.Y < pend Then

        '        'tooltip.SetToolTip(dgvCardNumber, db.getvalue("select * from employee where ecardnumber='" & dgvCardNumber.Rows(i).Cells("CardNumber").Value & "'", "efullname"))
        '        ToolTip.Show(db.getvalue("select * from employee where ecardnumber='" & dgvCardNumber.Rows(i).Cells("CardNumber").Value & "'", "efullname"), txtFind, MousePosition.X - Me.Location.X - txtFind.Location.X, MousePosition.Y - Me.Location.Y - txtFind.Location.Y - 22)
        '        Exit For
        '        'MsgBox("Row:" & i)
        '    End If
        '    pstart = pend
        'Next
    End Sub

    'Private Sub dgvCardNumber_RowEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCardNumber.RowEnter
    '    'If e.ColumnIndex = 0 Then
    '    '    ToolTip.Show(db.getvalue("select * from employee where ecardnumber='" & dgvCardNumber.Rows(e.RowIndex).Cells("CardNumber").Value & "'", "efullname"), txtFind, MousePosition.X - Me.Location.X - txtFind.Location.X, MousePosition.Y - Me.Location.Y - txtFind.Location.Y - 22)
    '    'End If
    'End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim CardNumber As String = ""
        If CardNumber.Length > 0 Then
            txtFind.Text = CardNumber
        End If
    End Sub

    Private Sub dgvCardNumber_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvCardNumber.CellContentClick
        If e.ColumnIndex = 0 Then
            ToolTip.Show(db.getvalue("select * from  Employee_CuChi  where ecardnumber='" & dgvCardNumber.Rows(e.RowIndex).Cells("CardNumber").Value & "'", "efullname"), txtFind, MousePosition.X - Me.Location.X - txtFind.Location.X, MousePosition.Y - Me.Location.Y - txtFind.Location.Y - 22)
        End If
    End Sub
End Class
